<?php
// 获取头像,通过数据库的相对路径

include '../init.php';

$uid = @$_GET['uid'];
if (empty($uid)){
	$realpath = UPLOAD_DIR.'avatar.jpeg';
	header('Content-type:image/png');
	readfile($realpath);
	exit();
}

make_avatar($uid);

function make_avatar($uid){
	$sql   = "SELECT fid,fpath,name FROM `uploadfile_tb` WHERE fid ";
	$sql  .= "in (SELECT avatarid FROM `userinfo_tb` WHERE uid=".$uid.") LIMIT 1 ;";
	$array = array();
	if (!my_mysql_query($sql, $array)) {
		var_dump('头像加载失败');
		exit();
	}
	
	$realpath = UPLOAD_DIR.$array[0]['fpath'];
	// var_dump($realpath);
	header('Content-type:image/png');
	readfile($realpath);
}